import React from 'react';
import {Select} from 'antd';
import axios from 'axios';
const Option = Select.Option;


class SelectComponents  extends React.Component {
    constructor(props) {		
        super(props);        
        this.state={
            default:'',
            content:[]
        }
        axios.get(this.props.url).then(res => {
            
			if (res && res.data) {
               //把结果放入select框中
               this.setState({
                    default:res.data[0].value,
                    content:[
                        ...res.data
                    ]
               })
            }
        });
    }

    handleChange=(value)=> {
        this.setState({
            default:value
        })
    }
    
    render(){
        return(
                <Select value={this.state.default} style={{ width: 120,marginRight:'20px' }} onChange={this.handleChange}>
                    {
                        this.state.content.map(function(child){
                            return (<Option key={child.value} value={child.value}>{child.name}</Option>)
                        })
                    }
                </Select>
        )
    }
}    
export default SelectComponents;